/////////
// Author: Nick Viselli
// Date: 3/16/2013
// Class: SGP1
// Last Modified: 3/16/2013 2:56 PM
// Purpose: Will handle all basic information for all classes
////////

#include "Entity.h"
#include "../../SGD_Wrappers/CSGD_TextureManager.h" 
#include "../../SGD_Wrappers/CSGD_EventSystem.h"
CEntity::CEntity(void)
{
	m_eType = ENTITY_ENTITY;
	m_fPosX = 0.0f;
	m_fPosY = 0.0f;
	m_fPrevPosX = 0.0f;
	m_fPrevPosY = 0.0f;
	m_fVelX = 0;
	m_fVelY = 0;
	m_nWidth = 64;
	m_nHeight = 64;
	m_nImage = -1;
	m_unReferences = 1;
}


CEntity::~CEntity(void)
{
}


void CEntity::Update(float fElapsedTime)
{
	m_fPrevPosX = m_fPosX;
	m_fPrevPosY = m_fPosY;
	m_fPosX += m_fVelX*fElapsedTime;
	m_fPosY += m_fVelY*fElapsedTime;
}

void CEntity::Render()
{
	CSGD_TextureManager::GetInstance()->Draw(m_nImage, (int)m_fPosX,(int)m_fPosY);
}

RECT CEntity::GetRect()
{
	RECT rSelf = {(LONG)(GetPosX() - GetWidth()/2.0f ),(LONG)(GetPosY() - GetHeight()/2.0f),
					(LONG)(GetPosX() + GetWidth()/2.0f),
					(LONG)(GetPosY() + GetHeight()/2.0f)};

	return rSelf;
}

bool CEntity::CheckCollision( IEntity* pOther)
{
	RECT rSelf = GetRect();
	RECT rOther = pOther->GetRect();
	RECT rOverlap;
	return (IntersectRect(&rOverlap, &rSelf, &rOther)==TRUE);
}

void CEntity::AddRef()
{
	++m_unReferences;
}

void CEntity::Release()
{
	--m_unReferences;

	if(m_unReferences <= 0)
		delete this;
}

void CEntity::HandleEvent(CEvent* pEvent)
{

}